package com.issc.DataBase;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import com.issc.bean.User;

public class DataBase {
	public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
		User user = new User();
		insert(user);
	}
	
	
	public static void insert(User user) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
		
		String url = "jdbc:mysql://localhost:3306/forum?useUnicode=true&characterEncoding=UTF8";
		try {
			Class.forName("com.mysql.jdbc.Driver").newInstance();
		} catch (InstantiationException | IllegalAccessException
				| ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}  
	    Connection conn=null;
		try {
			conn = DriverManager.getConnection(url,"root","");
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
	    String sql="insert into user(username,password,email) values(?,?,?)";
	    PreparedStatement pst;
		try {
			pst = conn.prepareStatement(sql);
			pst.setString(1,user.getUsername());
		    pst.setString(2,user.getPassword());
		    pst.setString(3,user.getEmail());
		    pst.executeUpdate();
		    
		    
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
